home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************
- #
- # utils.c
- #
- # This segment handles file parsing, and basic utility functions.
- #
- # Author(s): Michael Marinkovich
- # Apple Developer Technical Support
- # marink@apple.com
- #
- # Modification History:
- #
- # 2/10/96 MWM Initial coding
- #
- # Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
- #
- #
- # You may incorporate this sample code into your applications without
- # restriction, though the sample code has been provided "AS IS" and the
- # responsibility for its operation is 100% yours. However, what you are
- # not permitted to do is to redistribute the source as "DSC Sample Code"
- # after having made changes. If you're going to re-distribute the source,
- # we require that you make it clear in the source that the code was
- # descended from Apple Sample Code, but that you've made changes.
- #
- *************************************************************************************/
-
- #include <Events.h>
- #include <ToolUtils.h>
- #include <Gestalt.h>
- #include <OSUtils.h>
- #include <StandardFile.h>
-
- #include "App.h"
- #include "Proto.h"
-
-
- //----------------------------------------------------------------------
- //
- // PictToWorld - create a GWorld from a Pict. Size is determined by the
- // bounds of the pict. If the pict is nil then a default
- // bounds is used, in case of an empty window.
- //----------------------------------------------------------------------
-
- OSErr PictToWorld(PicHandle pict, short depth, GWorldPtr *theWorld)
- {
- OSErr err = noErr;
- GWorldPtr oldWorld;
- GDHandle oldGD;
- PixMapHandle thePix;
- Rect bounds;
-
- if (theWorld != nil && pict != nil)
- {
- *theWorld = nil;
- bounds = (**pict).picFrame;
-
- GetGWorld(&oldWorld, &oldGD);
-
- err = NewGWorld(theWorld, depth, &bounds, nil, nil, 0L);
-
- if (err == noErr && theWorld != nil)
- {
- thePix = GetGWorldPixMap(*theWorld);
-
- if (LockPixels(thePix))
- {
- SetGWorld(*theWorld, nil);
-
- EraseRect(&bounds);
- DrawPicture(pict, &bounds);
-
- UnlockPixels(thePix);
- }
-
- SetGWorld(oldWorld, oldGD);
- }
-
- }
- else
- err = paramErr;
-
-
- return err;
-
- }
-
-
- //----------------------------------------------------------------------
- //
- // ZeroRect - zero the top-left points of a rect
- //
- //
- //----------------------------------------------------------------------
-
- void ZeroRect(Rect *r)
- {
- Rect zr;
-
- zr = *r;
-
- if (zr.left < 0)
- OffsetRect(&zr,zr.left,0);
- if (zr.top < 0)
- OffsetRect(&zr,0,zr.top);
-
- OffsetRect(&zr,-zr.left,-zr.top);
-
- *r = zr;
-
- }
-
-
- //----------------------------------------------------------------------
- //
- // pstrcpy - pascal string copy
- //
- //
- //----------------------------------------------------------------------
-
- void pstrcpy(StringPtr dst, StringPtr src)
- {
- short c;
-
- for (c = *src; c > -1; c--)
- dst[c] = src[c];
- }
-
-
- //----------------------------------------------------------------------
- //
- // pstrcat - pascal string concat
- //
- //
- //----------------------------------------------------------------------
-
- void pstrcat(StringPtr dst, StringPtr src)
- {
-
- short c;
-
- for (c = 1; c < src[0] + 1; c++)
- dst[dst[0] + c] = src[c];
- dst[0] += src[0];
- }
-